﻿using Microsoft.AspNetCore.Http;
using SmartSiteManagementSystem.Models.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SmartSiteManagementSystem.AppApi.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class RequestHeadHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="httpRequest"></param>
        /// <returns></returns>
        public static ApiRequestCustomHeadInfo GetApiRequestCustomHeadInfo(HttpContext httpRequest)
        {
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = new ApiRequestCustomHeadInfo();
            if (httpRequest!=null)
            {
                var headers = httpRequest.Request.Headers;
                if (headers.Count > 0)
                {
                    if (headers.ContainsKey("version"))
                    {
                        apiRequestCustomHeadInfo.Version = headers["version"].FirstOrDefault().ToLowerInvariant();
                    }
                    if (headers.ContainsKey("platfrom"))
                    {
                        apiRequestCustomHeadInfo.PlatFrom = headers["platfrom"].FirstOrDefault().ToLowerInvariant();
                    }
                }

            }
            return apiRequestCustomHeadInfo;
        }
    }
}
